package adc.budget.ui.web.wicket;

import org.apache.wicket.Application;
import org.apache.wicket.Page;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Response;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import adc.budget.spec.bs.IAccountTypeBs;
import adc.budget.spec.bs.ICategoryBs;
import adc.budget.spec.bs.ISourceBs;

@Service
public class BudgetApplication extends WebApplication {
    
    @Autowired
    private IAccountTypeBs accountTypeBs;
    @Autowired
    private ICategoryBs categoryBs;
    @Autowired
    private ISourceBs sourceBs;

    @Override
    public Class<? extends Page> getHomePage() {
        return HomePage.class;
    }

    @Override
    public Session newSession(Request request, Response response) {
        return new BudgetSession(request);
    }

    public static BudgetApplication get() {
        return (BudgetApplication) Application.get();
    }

    public IAccountTypeBs getAccountTypeBs() {
        return accountTypeBs;
    }

    public ICategoryBs getCategoryBs() {
        return categoryBs;
    }

    public ISourceBs getSourceBs() {
        return sourceBs;
    }

    @Override
    protected void init() {
        super.init();
        this.getComponentInstantiationListeners().add(new SpringComponentInjector(this));
        mountPage("accountTypes", AccountTypePage.class);
        mountPage("accounts", AccountPage.class);
        mountPage("categories", CategoryPage.class);
        mountPage("transactions", TransactionPage.class);
    }
}
